Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Enumerable.Min/Max for all IBinaryIntegers #96605

Merged
merged 1 commit into from
Jan 8, 2024

Conversation

stephentoub
Copy link
Member

The implementations are special-casing most of the built-in ones, in order to delegate to the IBinaryInteger-constrained helper, but it was missing Int128, UInt128, and char. ?hese won't be vectorized, but they'll at least use the more streamlined non-vectorized implementations.

The implementations are special-casing most of the built-in ones, in order to delegate to the IBinaryInteger-constrained helper, but it was missing Int128, UInt128, and char. ?hese won't be vectorized, but they'll at least use the more streamlined non-vectorized implementations.
@stephentoub stephentoub added area-System.Linq tenet-performance Performance related issue labels Jan 8, 2024
@stephentoub stephentoub added this to the 9.0.0 milestone Jan 8, 2024
@ghost
Copy link

ghost commented Jan 8, 2024

Tagging subscribers to this area: @dotnet/area-system-linq
See info in area-owners.md if you want to be subscribed.

Issue Details

The implementations are special-casing most of the built-in ones, in order to delegate to the IBinaryInteger-constrained helper, but it was missing Int128, UInt128, and char. ?hese won't be vectorized, but they'll at least use the more streamlined non-vectorized implementations.

Author: stephentoub
Assignees: -
Labels:

area-System.Linq, tenet-performance

Milestone: 9.0.0

@ghost ghost assigned stephentoub Jan 8, 2024
Copy link
Member

@eiriktsarpalis eiriktsarpalis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If vectorization isn't available for the new types, what is the primary motivation for making this change? Is it that IBinaryInteger comparison is generally faster than using Comparer<TDefault>? Or is it simply the fact that we extract the span and avoid allocating an enumerator? If it's the latter case, couldn't this be extracted to the outer method so that it can be applied to all types?

@stephentoub
Copy link
Member Author

Previously a) it was a bit faster and b) IsSupported could ironically only be called with a supported type or else it would throw. But the former was improved in the JIT and the latter was fixed late in 8, so we should be able to make it work with an IComparable-based implementation. The primary benefit is being able to work on the span and avoid the enumerator costs.

@stephentoub
Copy link
Member Author

Although https://github.com/dotnet/runtime/pull/96570/files#diff-a7055cca652c7bf1b5af1f4f86111a7949edc40480117bf2fd7651b9338458ca needs to be merged first to remove the constraint from TryGetSpan.

@stephentoub
Copy link
Member Author

Since this is a small change, I suggest we merge this, and then we can subsequently look at improving Min/Max to use a span for other types. I have another branch where I'm doing so for more operators and I can incorporate it into that.

@stephentoub stephentoub merged commit 0823c5c into dotnet:main Jan 8, 2024
109 of 111 checks passed
@stephentoub stephentoub deleted the enumerableminmax branch January 8, 2024 16:34
@stephentoub
Copy link
Member Author

If it's the latter case, couldn't this be extracted to the outer method so that it can be applied to all types?

I gave this a go, and the reliance on Comparer<T>.Default yields a tad less efficient code in some of the cases. I'll try to revisit it again later.

agocke added a commit to agocke/runtime that referenced this pull request Jan 12, 2024
PR dotnet#96605 added new generic arguments to the unit tests which need to
be preserved in the rd.xml since the test suite is not yet trim-compatible.
@agocke agocke mentioned this pull request Jan 12, 2024
agocke added a commit that referenced this pull request Jan 13, 2024
PR #96605 added new generic arguments to the unit tests which need to
be preserved in the rd.xml since the test suite is not yet trim-compatible.
tmds pushed a commit to tmds/runtime that referenced this pull request Jan 23, 2024
PR dotnet#96605 added new generic arguments to the unit tests which need to
be preserved in the rd.xml since the test suite is not yet trim-compatible.
@github-actions github-actions bot locked and limited conversation to collaborators Feb 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Linq tenet-performance Performance related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants